from jsonpath_rw import parse
import requests
import json
from base.runmethod import RunMethod
class tsat:
    # 请求赠送特训营名额
    def givePartnerSeminarGift(self):
        url="http://testapi.jiahuiku.cn:9700/api/content/v1/seminarGiftLog/givePartnerSeminarGift"
        header={"Content-type": "application/json","Authorization": "eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiI0MDIiLCJ1c2VySWQiOiIyMDA1MTM0OTAyMTYyMzAwMTEiLCJuYW1lIjoibW9iaWxlIiwiZXhwIjozNzg4MTQ4MTk2fQ.KzaX-idj2lx6CcBJ1tZ0S5GrqY-VAlj9JyPHkjcTEjSVqihlo_48YtTxDctIQG06JucNYSOo5GgnvKHQWslk3hdK3GCdYRx1D6xvjeSwGclKZdg8UCRVdOO9AUBQXrypM62hyAEnwTotAhJxHDLcsudT7ewuLbGIlLTATwFOmb8"}
        data={"year":"2021","expireTime":"2023-01-01"}
        tet=RunMethod()
        tt = tet.run_main("get", url, data, header)
        print(tt)

        # tet=requests.post(url=url,data=json.dumps(data),header=header)


    def trequest(self):
        url="http://testapi.jiahuiku.cn:9700/api/auth/v1/token/mobile/v2"
        header={"Content-type": "application/json","Authorization": ""}
        data={"password":"123456","src":"mobile","mobile":"13955231435","systemType":2}
        # tt=requests.post(url=url, data=json.dumps(data), headers=header)
        # # tet=requests.post(url=url,data=data,header=header)
        # print(type(tt.text))
        # print(tt.text)
        tet=RunMethod()
        tt=tet.run_main("post",url,data,header)
        print(type(tt))
        print(tt)
        # tet.post_main()
        
# def get_key_from_data(key,data):
#     # 定义匹配规则
#     json_expr=parse(key)
#     result=json_expr.find(data)
#     # [match.value for match in male][0]
#     return [match.value for match in result]


if __name__ == '__main__':
    tdt=tsat()
    tdt.givePartnerSeminarGift()
    # key="msg"
    # key="data[*].uid"
    # key="$..uid"
    # data={"code":"00","msg":"success","data":[
    #     {"uid":"1","name":"zs","age":11},
    #     {"uid": "2", "name": "ls", "age": 12},
    #     {"uid": "3", "name": "ww", "age": 13}
    # ]}
    # print(get_key_from_data(key,data))